package ljl.alg.wangzheng_camp.round1.hashmap;

import java.util.*;

public class _49_group_anagram {
    
    /*
    * 要我说 我思路肯定是排序每一个数组，作为字符串类型 key，存进去
    * */
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> groups = new HashMap<>();
        for (String str : strs) {
            final char[] chars = str.toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            groups.computeIfAbsent(key, k -> new ArrayList<>()).add(str);
        }
        return new ArrayList<>(groups.values());
    }
    
}
